// 个人中心的控制器
angular.module('personalcenter.controller', ['personalcenter.service'])
    .controller("PersonalcenterCtrl", function ($scope, $ionicPopup,$rootScope,$http) {

        //检测更新弹出窗口
        $scope.showConfirm = function() {
            var confirmPopup = $ionicPopup.confirm({
                title: '<h3>发现新版本</h3>',
                subTitle:'<div><h4>有新版本可供更新(3.2M)</h4></div>',
                template: ' <p>1.功能完善</p> <p>2.页面及性能优化</p> <p>3.新增功能</p>',
                buttons: [{ text: '下次再说' }, {text: '立即更新', type: 'button-positive',}]
            });
            confirmPopup.then(function(res) {
                if(res) {
                    console.log('You are sure');
                } else {
                    console.log('You are not sure');
                }
            });
        };
        //接口
        var CCSessionId =localStorage.getItem("CCSessionId");
        var url =$rootScope.myglobal.serverurl+'/authority/baseuser/new.json?CCSessionId='+CCSessionId
        console.log(url);
        $http.get(url)
            .success(function(data){
                $scope.userName =data.userName;
                $scope.realName =data.realName;
                var tel = data.mobile;
                var reg = /(\d{3})\d{4}(\d{4})/;
                var getTel= tel.replace(reg,"$1****$2");
                $scope.mobile =getTel;
                var idcode = data.IDCode;
                var getcode= idcode.replace(idcode.substr(8,8), "********");
                $scope.IDCode =getcode
                console.log(data);
                console.log(data.userName);
            }).error(function(data){
                console.log(data);
            })



        //判断是否设置图案解锁
        var passwordxx = window.localStorage.getItem('passwordxx');
        console.log(passwordxx);
        if(passwordxx==null){
            $scope.set="未设置"
        }else{
            $scope.set="已设置"
        }

    })
